<?php
/**
 * This is a quick-and-dirty draft QPanel object to do Create, Edit, and Delete functionality
 * of the Meeting class.  It uses the code-generated
 * MeetingMetaControl class, which has meta-methods to help with
 * easily creating/defining controls to modify the fields of a Meeting columns.
 *
 * Any display customizations and presentation-tier logic can be implemented
 * here by overriding existing or implementing new methods, properties and variables.
 *
 * NOTE: This file is overwritten on any code regenerations.  If you want to make
 * permanent changes, it is STRONGLY RECOMMENDED to move both meeting_edit.php AND
 * meeting_edit.tpl.php out of this Form Drafts directory.
 *
 * @package My QCubed Application
 * @subpackage Drafts
 */
class MeetingHeaderPanel extends QPanel {
    // Local instance of the MeetingMetaControl
    public $mctMeeting;
    public $objMeeting;

    // Controls for Meeting's Data Fields

    public $calDate;
    public $txtLocation;
    public $txtSubject;

    public $btnSave;
    public $btnCancel;
    // Other ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References
    public $lstPeopleAsMembers;

    public $strSetEditPanelMethod;

    // Callback
    protected $strClosePanelMethod;

    public function __construct($objParentObject, $strSetEditPanelMethod, $mctMeeting, $strControlId = null) {
        // Call the Parent
        try {
            parent::__construct($objParentObject, $strControlId);
        } catch (QCallerException $objExc) {
            $objExc->IncrementOffset();
            throw $objExc;
        }

        // Setup Callback and Template
        $this->strTemplate = __DOCROOT__. __MEETING__ . '/tpl/MeetingHeaderPanel.tpl.php';

        $this->strSetEditPanelMethod = $strSetEditPanelMethod;
        // Construct the MeetingMetaControl
        // MAKE SURE we specify "$this" as the MetaControl's (and thus all subsequent controls') parent
        $this->mctMeeting = $mctMeeting;

        // Call MetaControl's methods to create qcontrols based on Meeting's data fields

        $this->calDate = $this->mctMeeting->calDate_Create();
        $this->calDate->Required= true;
        $this->txtLocation = $this->mctMeeting->txtLocation_Create();
        $this->txtSubject = $this->mctMeeting->txtSubject_Create();
        $this->lstPeopleAsMembers = $this->mctMeeting->lstPeopleAsMembers_Create();

        $this->btnSave = new QButton($this);
        $this->btnSave->Text = QApplication::Translate('Save');
        $this->btnSave->AddAction(new QClickEvent(), new QAjaxControlAction($this,'btnSave_Click'));
        $this->btnSave->CausesValidation = true;

        $this->btnCancel = new QButton($this);
        $this->btnCancel->Text = QApplication::Translate('Cancel');
        $this->btnCancel->AddAction(new QClickEvent(), new QAjaxControlAction($this,'btnCancel_Click'));

    }
    // Control AjaxAction Event Handlers
    public function btnSave_Click($strFormId, $strControlId, $strParameter) {
        // Delegate "Save" processing to the MeetingMetaControl
        $blnEdit= $this->mctMeeting->__get("EditMode");
        $this->mctMeeting->SaveMeeting();
        if (!$blnEdit) {
            $this->objMeeting= $this->mctMeeting->__get("Meeting");
            QApplication::Redirect(__MEETING__ . "/meeting_edit.php/".$this->objMeeting->Id);
        }
        else {
            QApplication::Redirect(__MEETING__ );
            $_SESSION['MeetingId'] = $this->objMeeting->Id;
            $objEditPanel = new MeetingNoteListPanel($this,"");
            $this->objForm->SetEditPane($objEditPanel, "pnlNoteList");
        }
    }


    public function btnCancel_Click($strFormId, $strControlId, $strParameter) {
        QApplication::Redirect(__MEETING__);
    }





}
?>